package com.zrrd.exam;

import com.zrrd.zuo.picture.Node;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;

/**
 * @author ywb
 * @Description:
 * @date 2023/4/13 19:13
 */
public class Solution {
    class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;
        }
    }
    public TreeNode valueOfTree (TreeNode root) {
        // write code here
        if(root == null){
            return null;
        }
        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        while(!queue.isEmpty()){
            TreeNode cur = queue.poll();
            pross(cur);
            if(cur.right != null) queue.add(cur.right);
            if(cur.left != null)  queue.add(cur.left);
        }
        return root;
    }
    public void pross(TreeNode node){

       if (node.right == null && node.left == null){
           node.val = 0;
           return;
       }

    int n = 1;
        int count = 0;
        Queue<TreeNode> queue= new LinkedList<>();
        queue.add(node);
        while(!queue.isEmpty()){
            TreeNode cur = queue.poll();
            n*=cur.val;
            if(cur.right != null) queue.add(cur.right);
            if(cur.left != null)  queue.add(cur.left);
        }
        if(n == 0){
            node.val = 1;
            return;
        }
        while (n%10 == 0){
            n = n/10;
            count++;
        }
        node.val = count;
        return;
    }




}